﻿using Coater.Domain;
using Coater.Helper;

namespace Coater.Dao
{
    public class IOInfoConfigDao
    {
        public async Task<List<IoInfo>> GetList()
        {
            SQLiteHelper.SetConnectionString("Coater");

            var sql = $"select * from io_config where Enable= true";
            var ioInfoList = await SQLiteHelper.ReadTypeItemsAsync<IoInfo>(sql);

            foreach (var infoConfig in ioInfoList)
            {
                sql = $"select * from ioinfo_config where IOConfigId = {infoConfig.Id} and Enable = true";
                var infoConfigList = await SQLiteHelper.ReadTypeItemsAsync<IoConfigInfo>(sql);
                infoConfig.IoConfigInfos = infoConfigList;
            }
            return ioInfoList;
        }
    }
}
